//package com.sunlands.zlcx.usercenter.config;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.crypto.password.StandardPasswordEncoder;
//import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
//import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
//import org.springframework.security.oauth2.provider.ClientDetailsService;
//import org.springframework.security.oauth2.provider.token.TokenStore;
//import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
//
///**
// * 认证服务器相关配置
// *
// * @author anjl
// */
//@SuppressWarnings("unused")
////@Configuration
////@EnableAuthorizationServer
//public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
//
//
//
////    @Override
////    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
////        security
////                .checkTokenAccess("isAuthenticated()")
////                .allowFormAuthenticationForClients();
////    }
////
////    /**
////     * 加载client 信息
////     *
////     * @param clients clients
////     * @throws Exception Exception
////     */
////    @Override
////    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
////        clients.withClientDetails(clientDetailsService);
////    }
////
////    @Override
////    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
////        //为了使用password授权模式需要注入authenticationManager
////        endpoints.authenticationManager(authenticationManager)
////                .userDetailsService(userDetailsService)
////                .tokenStore(tokenStore())
////        ;
////    }
////
////    /**
////     * redis 保存token
////     *
////     * @return TokenStore
////     */
////    @Bean
////    public TokenStore tokenStore() {
////        RedisTokenStore redisTokenStore = new RedisTokenStore(connectionFactory);
////        redisTokenStore.setPrefix("tongzhuo-auth-cache:");
////        return redisTokenStore;
////    }
////
////    private final AuthenticationManager authenticationManager;
////
////    private final RedisConnectionFactory connectionFactory;
////
////    private final ClientDetailsService clientDetailsService;
////
////    private final UserDetailsService userDetailsService;
////
////    @Autowired
////    public AuthorizationServerConfig(
////            //加入@Lazy否则会产生循环依赖
////            @Lazy AuthenticationManager authenticationManager,
////            @Lazy ClientDetailsService clientDetailsService,
////            RedisConnectionFactory connectionFactory, @Lazy UserDetailsService userDetailsService) {
////        this.authenticationManager = authenticationManager;
////        this.connectionFactory = connectionFactory;
////        this.clientDetailsService = clientDetailsService;
////        this.userDetailsService = userDetailsService;
////    }
////
////    @Configuration
////    public static class PasswordEncoderConfig {
////        /**
////         * 密码加密方式
////         *
////         * @return PasswordEncoder
////         */
////        @Bean
////        public PasswordEncoder passwordEncoder() {
////            return new UsersPasswordEncoder();
////        }
////    }
////
////    /**
////     * 自定义密码验证方式，如果微信登录没有密码时，使用"通用密码"登录。
////     */
////    static class UsersPasswordEncoder implements PasswordEncoder{
////        private StandardPasswordEncoder standardPasswordEncoder = new StandardPasswordEncoder();
////
////        @Override
////        public String encode(CharSequence rawPassword) {
////            return standardPasswordEncoder.encode(rawPassword);
////        }
////        @Override
////        public boolean matches(CharSequence rawPassword, String encodedPassword) {
////            return rawPassword.equals(GENERAL_PASSWORD) || standardPasswordEncoder.matches(rawPassword, encodedPassword);
////        }
////    }
//
//}
